package com.bradz.mytv;

import java.net.URL;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import android.util.Log;

public class classXMLParser {
	
	private String url;
	
	public void set_url(String url){
		this.url = url;
	}
	
	public String parse_for_youtube(){
    	String result = "";
		try{
			DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
			DocumentBuilder db = dbf.newDocumentBuilder();
			Document doc = db.parse(new URL(url).openStream());
			doc.getDocumentElement ().normalize ();
			NodeList content = doc.getElementsByTagName("media:content");
			for(int i=0; i<content.getLength(); i++){
				Element rsp = (Element)content.item(i);
                result = rsp.getAttribute("url");
			}

    	}catch(Exception e){
    		Log.e("log_tag", "Error in http connection "+e.toString());
    	}
		return result;
	}
}
